//
//  YQHomePageHeadView.m
//  NewRetail
//
//  Created by yuqin on 2019/6/30.
//  Copyright © 2019年 yuqin. All rights reserved.
//

#import "YQHomePageHeadView.h"

@interface YQHomePageHeadView ()

@property (nonatomic, strong) UIView *horizontalLineView;//横线

@property (nonatomic, strong) UIView *ordinateLineView;//纵线

@end

@implementation YQHomePageHeadView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupHeadView];
        self.layer.cornerRadius = 5;
        self.layer.masksToBounds = YES;
    }
    return self;
}

- (void)setupHeadView {
    [self addSubview:self.icon];
    [self.icon addSubview:self.addressLab];
    [self.icon addSubview:self.horizontalLineView];
    [self.icon addSubview:self.ordinateLineView];
    
    
    [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    
    [self.addressLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(FIT(40));
        make.top.mas_equalTo(FIT(15));
        make.size.mas_equalTo(CGSizeMake(ScreenWidth-FIT(112), FIT(15)));
    }];
#pragma mark - 这里大佬自己看下...
    CGFloat backView_W = (ScreenWidth-2*kMargin_left)/3.0;
    CGFloat backView_H = FIT(65);
    for (NSInteger i = 0; i < 2; i++) {
        for (NSInteger j = 0; j<2; j++) {
            //背景
            UIView *backView = [[UIView alloc] init];
            backView.backgroundColor = [UIColor clearColor];
            [self.icon addSubview:backView];
            //65  117
            [backView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(FIT(60)+backView_W*i);
                make.top.equalTo(self.addressLab.mas_bottom).mas_equalTo(FIT(30)+backView_H*j);
                make.size.mas_equalTo(CGSizeMake(backView_W, backView_H));
            }];
            
            //标题
            UILabel *theTitleLab = [YQViewFactory labelWithTextColor:WhiteColor textAlignment:NSTextAlignmentCenter fontSize:FIT(18) userBold:YES];
            [backView addSubview:theTitleLab];
            
            if (i == 0 && j == 0) {
                theTitleLab.text = @"普通余额";
            }else if (i == 0 && j == 1){
                theTitleLab.text = @"利息收益";
            }else if (i == 1 && j == 0){
                theTitleLab.text = @"孵化本金";
            }else {
                theTitleLab.text = @"分享收益";
            }
            [theTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(FIT(10));
                make.centerX.mas_equalTo(backView.mas_centerX);
                make.size.mas_equalTo(CGSizeMake(backView_W, FIT(15)));
            }];
            
            //值
            UILabel *fourLab = [YQViewFactory labelWithTextColor:WhiteColor textAlignment:NSTextAlignmentCenter fontSize:FIT(30) userBold:YES];
            [backView addSubview:fourLab];
            if (i == 0 && j == 0) {
                fourLab.text = @"10000";
                self.balanceLab = fourLab;
            }else if (i == 0 && j == 1){
                fourLab.text = @"10000";
                self.principalLab = fourLab;
            }else if (i == 1 && j == 0){
                fourLab.text = @"10000";
                self.interestLab = fourLab;
            }else {
                fourLab.text = @"10000";
                self.shareLab = fourLab;
            }
            [fourLab mas_makeConstraints:^(MASConstraintMaker *make) {
                make.bottom.mas_equalTo(-FIT(10));
                make.centerX.mas_equalTo(backView.mas_centerX);
                make.size.mas_equalTo(CGSizeMake(backView_W, FIT(25)));
            }];
        }
    }
    
    //横 竖线
    [self.horizontalLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.addressLab.mas_bottom).mas_equalTo(FIT(25));
        make.left.equalTo(self.principalLab.mas_right).mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(2, 2*backView_H));
    }];
    
    [self.ordinateLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(FIT(60));
        make.top.equalTo(self.balanceLab.mas_bottom).mas_equalTo(FIT(10));
        make.size.mas_equalTo(CGSizeMake(2*backView_W, 2));
    }];
    
}

- (UIImageView *)icon {
    if (!_icon) {
        _icon = [YQViewFactory imageViewWithImage:YQ_IMAGE(@"homepage_back")];
    }
    return _icon;
}

- (UILabel *)addressLab {
    if (!_addressLab) {
        _addressLab = [YQViewFactory labelWithTextColor:WhiteColor textAlignment:NSTextAlignmentCenter fontSize:kTheTitleFont userBold:YES];
        _addressLab.text = @"0x748523523982sefh";
    }
    return _addressLab;
}

- (UIView *)horizontalLineView {
    if (!_horizontalLineView) {
        _horizontalLineView = [[UIView alloc] init];
        _horizontalLineView.backgroundColor = WhiteColor;
    }
    return _horizontalLineView;
}

- (UIView *)ordinateLineView {
    if (!_ordinateLineView) {
        _ordinateLineView = [[UIView alloc] init];
        _ordinateLineView.backgroundColor = WhiteColor;
    }
    return _ordinateLineView;
}

@end
